package com.android.vmg;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.*;

public class Game extends Activity {
	
	public class GameListener {
		Game mGame;
		public GameListener(Game gameActivity) {
			mGame = gameActivity;
		}
		public void gameEnd() {
			mGame.onDestroy();
		}
	}
	
	private GameThread mGameThread;
	private GameView mGameView;
	
	@Override
	public void onCreate(Bundle savedState) {
		super.onCreate(savedState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.game);
		mGameView = (GameView)findViewById(R.id.gameView1);
		mGameThread = (mGameView).getThread();
		try {
			Bundle b = getIntent().getExtras();
			int numCircles = b.getInt("numCircles");
			mGameThread.setListener(new GameListener(this));
			mGameThread.populate(numCircles, 1, 2*numCircles);
		} catch (Exception e) { }
/*		try {
			mGameView = (GameView)findViewById(R.id.gameView1);
			mGameThread = mGameView.getThread();
			mGameThread.setState(GameView.GameThread.READY);
			if(savedState == null) {
				mGameThread.setState(GameView.GameThread.READY);
				Log.w(getClass().getName(), "SIS == null");
			} else {
				mGameThread.restoreState(savedState);
				Log.w(getClass().getName(), "SIS != null");
			}
		} catch (Exception e) {
			Log.w("exception", e.getMessage());
		}*/
	}
	
	@Override
	public void onDestroy() {
		back(mGameView);
		super.onDestroy();
	}
	
	public void back(View v) {
		Intent intent = new Intent();
		intent.putExtra("state", mGameThread.gameState());
		intent.putExtra("points", mGameThread.getPoints());
		setResult(RESULT_OK, intent);
		finish();
	}
}
